<template>
    <div class="app-container">
        <div>
            <p class="dialogTitle title">当前地震事件:
                <span v-if="currentEvent">{{ currentEvent.eventName }}</span>
                <span v-else>请在地震事件管理中设置当前地震事件</span>
            </p>
        </div>

        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px" v-show="showSearch">
            <el-form-item label="拟定烈度" prop="intensityDetermination">
                <el-select v-model="queryParams.intensityDetermination" placeholder="请选择拟定烈度" clearable>
                    <el-option v-for="item in option" :key="item.dictItemCode" :label="item.dictItemName" :value="item.dictItemCode">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="抽样点名称" prop="samplingPointName">
                <el-input v-model="queryParams.samplingPointName" placeholder="请输入抽样点名称" clearable />
            </el-form-item>
            <el-form-item label="样本点房屋编号" prop="samplingPointHouseCode">
                <el-input v-model="queryParams.samplingPointHouseCode" placeholder="请输入样本点房屋编号" clearable />
            </el-form-item>
            <el-form-item label="调查员" prop="createUserName">
                <el-input v-model="queryParams.createUserName" placeholder="请输入调查员" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleQuery">搜索</el-button>
                <el-button @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
        	<el-col :span="1.5">
                <el-button type="primary" :disabled="!currentEvent" @click="handleImport">导入</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" :disabled="!currentEvent || dataList.length == 0"
                    @click="handleExport">导出</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList" stripe>
            <el-table-column label="序号" align="center" width="55">
                <template #default="scope">
                    <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="抽样点房屋编号" align="center" prop="samplingPointHouseCode">
                <template #default="scope">
                    <span style="color: #107ce1;cursor: pointer;" @click="handleEdit(scope.row)">{{
                        scope.row.samplingPointHouseCode
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="抽样点名称" align="center" prop="samplingPointName" />
            <el-table-column label="拟定烈度" align="center" prop="intensityDetermination">
                <template #default="scope">
                    {{getIntensityDetermination(scope.row.intensityDetermination)}}
                </template>
            </el-table-column>
            <el-table-column label="人员伤亡" align="center">
                <template #default="scope">
                    <el-button type="text" @click="handleDelite1(scope.row)">详情查看</el-button>
                </template>
            </el-table-column>
            <el-table-column label="宏观信息" align="center">
                <template #default="scope">
                    <el-button type="text" @click="handleDelite2(scope.row)">详情查看</el-button>
                </template>
            </el-table-column>
            <el-table-column label="宏观异常现象" align="center" prop="macroscopicAnomaly">
	            <template #default="scope">
			      		<span v-for="(item, index) in scope.row.macroscopicAnomaly.split(',')" :key="index" v-if="scope.row.macroscopicAnomaly">
			      			{{transMacroscopicAnomaly(item)}}
	              	        <span v-if ="index!==scope.row.macroscopicAnomaly.split(',').length-1 ">,</span>
			      		</span>
                        <span v-else></span>
			        </template>
			      </el-table-column>
            <el-table-column label="地质灾害" align="center" prop="geologicHazard">
            	<template #default="scope">
			      		<span v-for="(item, index) in scope.row.geologicHazard.split(',')" :key="index" v-if="scope.row.geologicHazard">
			      			{{transGeologicHazard(item)}}
	              	        <span v-if ="index!==scope.row.geologicHazard.split(',').length-1 ">,</span>
			      		</span>
                        <span v-else></span>
			        </template>
			      </el-table-column>
            <el-table-column label="调查点震前遥感图" align="center" prop="beforeEarthquakePicture">
                <template #default="scope">
                    <template v-if="scope.row.beforeEarthquakePicture">
                        <el-popover placement="left-start" width="400" trigger="click">
                            <template #reference>
                                <img :src="baseUrl + scope.row.beforeEarthquakePicture[0].attachId"
                                    :alt="baseUrl + scope.row.beforeEarthquakePicture[0].attachId" class="img" />
                            </template>
                            <template #default>
                                <img :src="baseUrl + scope.row.beforeEarthquakePicture[0].attachId" alt=""
                                    class="big" />
                            </template>
                        </el-popover>
                    </template>
                    <template v-else></template>
                </template>
            </el-table-column>
            <el-table-column label="调查后震前遥感图" align="center" prop="afterEarthquakePicture">
                <template #default="scope">
                    <template v-if="scope.row.afterEarthquakePicture">
                        <el-popover placement="left-start" width="400" trigger="click">
                            <template #reference>
                                <img :src="baseUrl + scope.row.afterEarthquakePicture[0].attachId"
                                    :alt="baseUrl + scope.row.afterEarthquakePicture[0].attachId" class="img" />
                            </template>
                            <template #default>
                                <img :src="baseUrl + scope.row.afterEarthquakePicture[0].attachId" alt="" class="big" />
                            </template>
                        </el-popover>
                    </template>
                    <template v-else></template>
                </template>
            </el-table-column>
            <el-table-column label="调查员" align="center" prop="createUserName" />
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
            @pagination="getList" />


        <el-dialog title="查看抽样点房屋数据" v-model="open" width="900px" append-to-body>
            <el-form ref="addRef" label-width="150px" :model="form">
                <el-row style="margin: 20px 0;">
                    <el-col :span="24">
                        <el-form-item label="行政区划" required>
                            <span>{{ form.province }}{{ form.city }}{{ form.area }}{{ form.address }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点名称" required prop="samplingPointName">
                            <el-input v-model="form.samplingPointName" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="经度" required prop="longitude">
                            <el-input v-model="form.longitude" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="纬度" required prop="latitude">
                            <el-input v-model="form.latitude" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点户数">
                            <el-input v-model="form.samplingPointHouseholds" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="户均房屋面积(平米)">
                            <el-input v-model="form.perHouseholdArea" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点人口">
                            <el-input v-model="form.samplingPointPopulation" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="房屋典型破坏情况" required prop="houseTypicalDamage">
                            <image-upload v-model="form.houseTypicalDamage" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-table style="margin-bottom: 40px;" :data="form.staResult" stripe>
                            <el-table-column label="结构类型" align="center" prop="structureType" >
                            	<template #default="scope">					
											          {{getStructureType(scope.row.structureType)}}
											        </template>
											      </el-table-column>
                            <el-table-column label="毁坏" align="center" prop="destroyArea">
                                <template #default="scope">
                                    <p>{{ scope.row.destroyArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.destroyScale }}%</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="严重破坏" align="center" prop="seriousDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.seriousDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.seriousDamageScale }}%</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="中等破坏" align="center" prop="moderateDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.moderateDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.moderateDamageScale }}%</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="轻微破坏" align="center" prop="minorDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.minorDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.minorDamageScale }}%</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="基本完好" align="center" prop="basicallyIntactArea">
                                <template #default="scope">
                                    <p>{{ scope.row.basicallyIntactArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.basicallyIntactScale }}%</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="总面积（平米）" align="center" prop="totalArea" />
                            <el-table-column label="震害指数" align="center" prop="damageIndex">
                                <template #default="scope">
                                    {{decimalTruncation(scope.row.damageIndex)}}
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                    <!-- 人员伤亡情况 -->
                    <el-col class="tab-title">人员伤亡情况</el-col>
                    <el-col :span="12">
                        <el-form-item label="死亡人数">
                            <el-input v-model="form.deathToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="失踪人数">
                            <el-input v-model="form.disappearToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="重伤人数">
                            <el-input v-model="form.seriousInjuryToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="轻伤人数">
                            <el-input v-model="form.minorWoundToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="宏观异常现象" prop="macroscopicAnomaly">
                            <el-select v-model="form.macroscopicAnomaly" multiple  style="width: 100%"
                                disabled>
                                <el-option v-for="item in option5" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="地质灾害" prop="geologicHazard">
                            <el-select v-model="form.geologicHazard" multiple  style="width: 100%"
                                disabled>
                                <el-option v-for="item in option6" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="建筑物震害特征描述">
                            <el-select v-model="form.buildingEarthquakeDescription" multiple 
                                style="width: 100%" disabled>
                                <el-option v-for="item in option7" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="震害特征描述补充">
                            <el-input v-model="form.earthquakeDescription" type="textarea" maxlength="500"
                                show-word-limit :autosize="{ minRows: 5, maxRows: 5 }" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查点震前遥感图">
                            <file-upload v-model="form.beforeEarthquakePicture" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查点震后遥感图">
                            <file-upload v-model="form.afterEarthquakePicture" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="无人机航拍1">
                            <file-upload v-model="form.uavAerialPhotographyOne" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="无人机航拍2">
                            <file-upload v-model="form.uavAerialPhotographyTwo" disabled />
                        </el-form-item>
                    </el-col>
                    <!-- 宏观信息 -->
                    <el-col class="tab-title">宏观信息</el-col>
                    <el-col :span="12">
                        <el-form-item label="地形地貌">
                            <el-select v-model="form.topographicFeatures" style="width: 100%;" disabled>
                                <el-option v-for="item in option1" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人员震感情况">
                            <el-select v-model="form.personnelShock" style="width: 100%;" disabled>
                                <el-option v-for="item in option2" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="器皿反应情况">
                            <el-select v-model="form.reactionOfVessels" style="width: 100%;" disabled>
                                <el-option v-for="item in option3" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="宏观描述">
                            <el-input v-model="form.macroDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="大范围照片">
                            <file-upload v-model="form.largeScalePhoto" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="大范围视频">
                            <file-upload v-model="form.largeScaleVideo" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="烈度拟定" required prop="intensityDetermination">
                            <el-select v-model="form.intensityDetermination" disabled>
                                <el-option v-for="item in option" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="灾情描述">
                            <el-input v-model="form.disasterDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="照片">
                            <file-upload v-model="form.enclosurePhoto" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="视频">
                            <file-upload v-model="form.enclosureVideo" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="音频">
                            <file-upload v-model="form.enclosureAudio" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="相册">
                            <file-upload v-model="form.enclosureAlbum" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="open = false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="查看人员伤亡" v-model="open1" width="400px" append-to-body>
            <el-form ref="addRef1" label-width="70px" :model="form1">
                <el-row style="margin: 20px 0;">
                    <el-col>
                        <el-form-item label="死亡人数">
                            <el-input v-model="form1.deathToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="失踪人数">
                            <el-input v-model="form1.disappearToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="重伤人数">
                            <el-input v-model="form1.seriousInjuryToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="轻伤人数">
                            <el-input v-model="form1.minorWoundToll" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="open1 = false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="查看宏观信息" v-model="open2" width="800px" append-to-body>
            <el-form ref="addRef2" label-width="120px" :model="form2">
                <el-row style="margin: 20px 0;">
                    <el-col :span="12">
                        <el-form-item label="地形地貌">
                            <el-select v-model="form2.topographicFeatures" style="width: 100%;" disabled>
                                <el-option v-for="item in option1" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人员情况">
                            <el-input v-model="form2.personnelShock" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="器皿反应情况">
                            <el-select v-model="form2.reactionOfVessels" style="width: 100%;" disabled>
                                <el-option v-for="item in option3" :key="item.dictItemCode" :label="item.dictItemName"
                                    :value="item.dictItemCode">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="宏观描述">
                            <el-input v-model="form2.macroDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="大范围照片">
                            <image-upload v-model="form2.largeScalePhoto" :limit="1" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="大范围视频">
                            <template v-if="form2.largeScaleVideo">
                                <video controls :src="baseUrl + form2.largeScaleVideo" id="videoId" autoplay
                                    style="width:100%"></video>
                            </template>
                            <template v-else>无</template>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="open2 = false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>
        <!-- 选择抽样点对话框 -->
        <el-dialog title="选择抽样点" v-model="selectPoint" width="1300px" append-to-body>
        	<p></p>
        	<el-table v-loading="loading1" :data="dataList1" stripe row-key="id" @row-click="singleElection">
            <el-table-column align="center" width="80" label="请选择">
				      <template #default="scope">
				      <!-- 可以手动的修改label的值，从而控制选择哪一项 -->
				      <el-radio
				      class="radio"
				      v-model="templateSelection"
				      :label="scope.row.samplingPointCode"
				      ><span></span></el-radio>
				      </template>
      			</el-table-column>
            <el-table-column label="评估子区名称" align="center" prop="evaluationSubareaName" />
            <el-table-column label="评估子区类别" align="center" prop="evaluationSubareaType" />
            <el-table-column label="抽样点编号" align="center" prop="samplingPointCode" />
            <el-table-column label="抽样点名称" align="center" prop="samplingPointName" />
            <el-table-column label="省" align="center" prop="province" />
            <el-table-column label="市" align="center" prop="city" />
            <el-table-column label="县" align="center" prop="area" />
            <el-table-column label="详细地址" align="center" prop="address" />
            <el-table-column label="创建人" align="center" prop="createUserName" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="100">
	            <template #default="scope">
	               <span>{{ parseTime(scope.row.createTime) }}</span>
	            </template>
	         </el-table-column>
        	</el-table>
        	<pagination v-show="total1 > 0" :total="total1" v-model:page="queryParams1.page" v-model:limit="queryParams1.rows"
            @pagination="getList1" />
        	<template #footer>
              <div class="dialog-footer">
                  <el-button type="primary" @click="nextStep">下一步</el-button>
                  <el-button @click="selectPoint = false">取 消</el-button>
              </div>
          </template>
        </el-dialog>
        <!-- 导入对话框 -->
        <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
          <p></p>
          <el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
              :disabled="upload.isUploading" :before-upload="handleFileBeforeUpload"
              :on-progress="handleFileUploadProgress" :on-error="handleFileUploadError" :on-success="handleFileSuccess"
              :data="{ 'xsemId': currentEvent.id }" :auto-upload="false" drag>
              <el-icon class="el-icon--upload"><upload-filled /></el-icon>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
              <template #tip>
                  <div class="el-upload__tip text-center">
                      <span>仅允许导入xls、xlsx格式文件。</span>
                       <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                          @click="importTemplate('抽样点房屋数据.xlsx')">下载模板</el-link> 
                  </div>
              </template>
          </el-upload>
          <template #footer>
              <div class="dialog-footer">
                  <el-button type="primary" @click="submitFileForm">确 定</el-button>
                  <el-button @click="upload.open = false">取 消</el-button>
              </div>
          </template>
        </el-dialog>
    </div>
</template>

<script setup name="samplePointHouseCheck">
import useEventStore from "@/store/modules/event";
import { getAllList, getDetail, getSamPoiByXsemId } from "@/api/disasterManage/fieldSurveyManage/samplePointHouseCheck.js"
import { getToken } from "@/utils/auth";
import { getDict } from "@/api/system/dict";
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const dataList1 = ref([]);
const ids = ref();
const loading = ref(false);
const loading1 = ref(false);
const single = ref(true);
const multiple = ref(true);
const open = ref(false);
const open1 = ref(false);
const open2 = ref(false);
const selectPoint = ref(false);
const total = ref(0);
const total1 = ref(0);
const templateSelection = ref("");
const templateData = ref({});
const showSearch = ref(true);
// 烈度拟定
const option = ref([]);
// 地形地貌
const option1 = ref([]);
// 人员震感情况
const option2 = ref([]);
// 器皿反应情况
const option3 = ref([]);
const option5 = ref([]);
const option6 = ref([]);
const option7 = ref([]);
const option8 = ref([]);
const currentEvent = computed(() => useEventStore().currentEvent);
const baseUrl = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoadFile?attachId=";
/*** 导入参数 */
const upload = reactive({
    open: false,
    title: "",
    isUploading: false,
    headers: { token: "token " + getToken() },
    url: import.meta.env.VITE_APP_BASE_API + "/samPoiHouSur/importExcel"
});
const playerOptions = ref({
    width: '800px', //播放器高度
    height: '450px', //播放器高度
    color: "#409eff", //主题色
    muted: false, //静音
    webFullScreen: false,
    speedRate: ["0.75", "1.0", "1.25", "1.5", "2.0"], //播放倍速
    autoPlay: false, //自动播放
    loop: false, //循环播放
    mirror: false, //镜像画面
    ligthOff: false,  //关灯模式
    volume: 0.3, //默认音量大小
    control: true, //是否显示控制器
    title: '', //视频名称
    src: "http://vjs.zencdn.net/v/oceans.mp4", //视频源
    poster: '', //封面
});
const data = reactive({
    queryParams: {
        page: 1,
        rows: 10,
        intensityDetermination: undefined,
        samplingPointName: undefined,
        samplingPointHouseCode: undefined,
        createUserName: undefined,
    },
    queryParams1: {
        page: 1,
        rows: 10,
    },
    form: {},
    form1: {},
    form2: {},
})
const { queryParams, queryParams1, form, form1, form2 } = toRefs(data)

function handleDelite1(row) {
    form1.value.deathToll = row.deathToll;
    form1.value.disappearToll = row.disappearToll;
    form1.value.seriousInjuryToll = row.seriousInjuryToll;
    form1.value.minorWoundToll = row.minorWoundToll;
    open1.value = true;
    proxy.resetForm("addRef1");
}

function handleDelite2(row) {
    form2.value.topographicFeatures = row.topographicFeatures;
    form2.value.personnelShock = row.personnelShock;
    form2.value.reactionOfVessels = row.reactionOfVessels;
    form2.value.macroDescription = row.macroDescription;
    form2.value.largeScalePhoto = row.largeScalePhoto;
    form2.value.largeScaleVideo = row.largeScaleVideo;
    open2.value = true;
    proxy.resetForm("addRef2");
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.page = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    dataList.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
    proxy.downloadTemplate('/samPoiHouSur/exportExcel', {...queryParams.value, xsemId: currentEvent.value.id }, `抽样点房屋数据.xls`)
}
// 导出模版
function importTemplate(name) {
    proxy.downloadTemplate("/template/download", {
        fileName: name
    }, name);
};
//单选
function singleElection(row) {
  templateSelection.value = row.samplingPointCode;
  templateData.value = row;
  //console.log(templateSelection.value)

}
/** 打开选择抽样点弹窗 */
function handleImport() {
	//selectPoint.value = true;    
  //getList1();
  upload.title = "导入";
  upload.open = true;
    
}
//获取抽样点数据列表
function getList1(){
	if (currentEvent.value) {
      loading1.value = true;
      getSamPoiByXsemId({ ...queryParams1.value, xsemId: currentEvent.value.id}).then(response => {
          dataList1.value = response.data.rows ? response.data.rows : [];
          total1.value = response.data.total;
          loading1.value = false;
      });
  } else {
      dataList1.value = [];
      total1.value = 0;
  }
}
/** 打开导入表弹窗 */
function nextStep() {
	if(!templateSelection.value){
		proxy.$modal.msgWarning("请选择抽样点");
		return;
	}
  upload.title = "导入";
  upload.open = true;
}
/** 提交上传文件 */
function submitFileForm() {
    proxy.$refs["uploadRef"].submit();
};


/**文件上传前处理 */
function handleFileBeforeUpload(file) {
    proxy.$modal.loading("正在上传文件，请稍候...");
    return true
}

/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
    upload.isUploading = true;
};
// 上传失败
function handleFileUploadError(err) {
    proxy.$modal.closeLoading();
    proxy.$modal.msgError("上传文件失败");
}
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
    upload.open = false;
    upload.isUploading = false;
    proxy.$modal.closeLoading();
    proxy.$refs["uploadRef"].handleRemove(file);
    proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +  response.data?response.data:response.message + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
    getList();
};
// 编辑
function handleEdit(row) {
    detail(row.id);
}

// 查看s
function detail(id) {
    getDetail({ id: id }).then(res => {
        open.value = true;
        proxy.resetForm("addRef");
        form.value = res.data;
        if(form.value.buildingEarthquakeDescription){
        	form.value.buildingEarthquakeDescription = form.value.buildingEarthquakeDescription.split(',');
        }
        if(form.value.geologicHazard){
        	form.value.geologicHazard = form.value.geologicHazard.split(',');
        }
        if(form.value.macroscopicAnomaly){
        	form.value.macroscopicAnomaly = form.value.macroscopicAnomaly.split(',');
        }
    })
}

/** 查询数据列表 */
function getList() {
    if (currentEvent.value) {
        loading.value = true;
        getAllList({ ...queryParams.value, xsemId: currentEvent.value.id }).then(response => {
            dataList.value = response.data.rows ? response.data.rows : [];
            total.value = response.data.total;
            loading.value = false;
        });
    } else {
        dataList.value = [];
        total.value = 0;
    }
}
/** 获取字典值 */
async function getDictData() {
	await getDict("dxdm").then(response => {
	    option1.value = response.data;
	});
	await getDict("ryzgqk").then(response => {
	    option2.value = response.data;
	});
	await getDict("ldnd").then(response => {
	    option.value = response.data;
	});
	await getDict("qmfyqk").then(response => {
	    option3.value = response.data;
	});
	await getDict("hgycxx").then(response => {
	    option5.value = response.data;
	});
	await getDict("dzzh").then(response => {
	    option6.value = response.data;
	});
	await getDict("jzwzhtzms").then(response => {
	    option7.value = response.data;
	});
	await getDict("jglx").then(response => {
	    option8.value = response.data;
	});
}
function getIntensityDetermination(val){
	var name = ''
  option.value.forEach(item => {
		if(item.dictItemCode == val) {
			name = item.dictItemName
			return
		}
	})
	return name
}
function transMacroscopicAnomaly(val){
	var name = ''
  option5.value.forEach(item => {
		if(item.dictItemCode == val) {
			name = item.dictItemName
			return
		}
	})
	return name
}
function transGeologicHazard(val){
	var name = ''
  option6.value.forEach(item => {
		if(item.dictItemCode == val) {
			name = item.dictItemName
			return
		}
	})
	return name
}
function getStructureType(val){
  var name = ''
  option8.value.forEach(item => {
		if(item.dictItemCode == val) {
			name = item.dictItemName
			return
		}
	})
	return name
}
function decimalTruncation(val) {
    let num = ''
    if(val != undefined) {
        let a = parseFloat(val)
        num = Math.ceil(a * 100) / 100
    }
    return num
}
onMounted(() => {
    setTimeout(() => {
        getList();
    }, 200)
})
getDictData();
</script>

<style scoped lang="scss">
.title {
    margin: 0 0 20px !important;
}

.tab-title {
    font-size: 16px;
    font-weight: bold;
    border-left: 4px solid #0D9AFF;
    font-family: PingFangSC-Medium;
    padding-left: 10px;
    margin-bottom: 20px;
}

.img {
    width: 80px;
    height: 80px;
    padding: 10px;
}

.big {
    width: 400px;
    padding: 20px;
}
</style>

